package vip.xiaonuo.supplier.modular.base.brands.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.base.brands.entity.SupplierBrands;
import vip.xiaonuo.supplier.modular.base.brands.param.SupplierBrandsAddParam;
import vip.xiaonuo.supplier.modular.base.brands.param.SupplierBrandsEditParam;
import vip.xiaonuo.supplier.modular.base.brands.param.SupplierBrandsIdParam;
import vip.xiaonuo.supplier.modular.base.brands.param.SupplierBrandsPageParam;
import vip.xiaonuo.supplier.modular.base.brands.service.SupplierBrandsService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 品牌信息控制器
 *
 * @author Mr.wu
 * @date  2025/02/28 21:42
 */
@Tag(name = "品牌信息控制器")
@RestController
@Validated
public class SupplierBrandsController {

    @Resource
    private SupplierBrandsService supplierBrandsService;

    /**
     * 获取品牌信息分页
     *
     * @author Mr.wu
     * @date  2025/02/28 21:42
     */
    @Operation(summary = "获取品牌信息分页")
    @SaCheckPermission("/supplier/base/brands/page")
    @GetMapping("/supplier/base/brands/page")
    public CommonResult<Page<SupplierBrands>> page(SupplierBrandsPageParam supplierBrandsPageParam) {
        return CommonResult.data(supplierBrandsService.page(supplierBrandsPageParam));
    }

    /**
     * 添加品牌信息
     *
     * @author Mr.wu
     * @date  2025/02/28 21:42
     */
    @Operation(summary = "添加品牌信息")
    @CommonLog("添加品牌信息")
    @SaCheckPermission("/supplier/base/brands/add")
    @PostMapping("/supplier/base/brands/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierBrandsAddParam supplierBrandsAddParam) {
        supplierBrandsService.add(supplierBrandsAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑品牌信息
     *
     * @author Mr.wu
     * @date  2025/02/28 21:42
     */
    @Operation(summary = "编辑品牌信息")
    @CommonLog("编辑品牌信息")
    @SaCheckPermission("/supplier/base/brands/edit")
    @PostMapping("/supplier/base/brands/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierBrandsEditParam supplierBrandsEditParam) {
        supplierBrandsService.edit(supplierBrandsEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除品牌信息
     *
     * @author Mr.wu
     * @date  2025/02/28 21:42
     */
    @Operation(summary = "删除品牌信息")
    @CommonLog("删除品牌信息")
    @SaCheckPermission("/supplier/base/brands/delete")
    @PostMapping("/supplier/base/brands/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierBrandsIdParam> supplierBrandsIdParamList) {
        supplierBrandsService.delete(supplierBrandsIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取品牌信息详情
     *
     * @author Mr.wu
     * @date  2025/02/28 21:42
     */
    @Operation(summary = "获取品牌信息详情")
    @SaCheckPermission("/supplier/base/brands/detail")
    @GetMapping("/supplier/base/brands/detail")
    public CommonResult<SupplierBrands> detail(@Valid SupplierBrandsIdParam supplierBrandsIdParam) {
        return CommonResult.data(supplierBrandsService.detail(supplierBrandsIdParam));
    }
}
